// kernel/vm.h
#ifndef _VM_H_
#define _VM_H_

#include "types.h"
#include "riscv.h"

typedef uint64 pte_t;
typedef pte_t* pagetable_t; // 512个PTE

#define MAXVA (1L << (9 + 9 + 9 + 12 - 1))

// 页表操作接口
pagetable_t create_pagetable(void);
void free_pagetable(pagetable_t pt, int level);
int map_page(pagetable_t pt, uint64 va, uint64 pa, int perm);
int unmap_page(pagetable_t pt, uint64 va);
pte_t* walk_lookup(pagetable_t pt, uint64 va);
pte_t* walk_create(pagetable_t pt, uint64 va, int alloc);
void dump_pagetable(pagetable_t pt, int level);

#endif